package com.fenrirtec.aepp.common.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fenrirtec.aepp.common.condition.TenderCondition;
import com.fenrirtec.aepp.common.dao.TenderDao;
import com.fenrirtec.aepp.common.model.Member;
import com.fenrirtec.aepp.common.model.TenderBid;
import com.fenrirtec.aepp.common.model.TenderDetail;
import com.fenrirtec.aepp.common.model.TenderEnroll;
import com.fenrirtec.aepp.common.model.TenderFinalist;
import com.fenrirtec.aepp.common.model.TenderInvite;
import com.fenrirtec.aepp.common.model.TenderMemberStatus;
import com.fenrirtec.aepp.common.model.TenderProduct;
import com.fenrirtec.aepp.common.model.TenderQuote;
import com.fenrirtec.aepp.common.model.TenderQuoteDetail;
import com.fenrirtec.core.database.DatabaseSessionManager;
import com.fenrirtec.core.database.ResultSetMapper;
import com.fenrirtec.core.exception.DatabaseException;

public class TenderDao_JDBCImpl implements TenderDao {
    
	private static final Logger logger = LoggerFactory.getLogger(TenderDao_JDBCImpl.class);

    @Override
    public Integer countByCnd(TenderCondition condition) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#countByCnd] start.");
        }

        PreparedStatement statement = null;
        
        int count = 0;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  count(tender_id) as count \n")
                .append("from \n")
                .append("  v_tender_information \n")
                .append("where \n")
                .append("  delete_flag = false \n");
            
            if (condition != null) {
                if (StringUtils.isNotEmpty(condition.getTenderTitle())) {
                    sql.append("and \n");
                    sql.append("  tender_title like ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateFrom())) {
                    sql.append("and \n");
                    sql.append("  enroll_start_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateTo())) {
                    sql.append("and \n");
                    sql.append("  enroll_start_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateFrom())) {
                    sql.append("and \n");
                    sql.append("  enroll_end_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateTo())) {
                    sql.append("and \n");
                    sql.append("  enroll_end_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateFrom())) {
                    sql.append("and \n");
                    sql.append("  tender_end_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateTo())) {
                    sql.append("and \n");
                    sql.append("  tender_end_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateFrom())) {
                    sql.append("and \n");
                    sql.append("  publish_result_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateTo())) {
                    sql.append("and \n");
                    sql.append("  publish_result_date <= ? \n");
                }
                if (condition.getTenderPattern() != null && condition.getTenderPattern().intValue() > 0) {
                    sql.append("and \n");
                    sql.append("  tender_pattern = ? \n");
                }
                if (condition.getStatus() != null && condition.getStatus().length > 0) {
                    sql.append("and \n");
                    String strStatus = "";
                    for (int i = 0; i < condition.getStatus().length; i++) {
                        if (i == 0) {
                            strStatus = "?";
                        } else {
                            strStatus += ", ?";
                        }
                    }
                    sql.append("  status in (" + strStatus + ") \n");
                }
                if (condition.getTimeLimit() != null && condition.getTimeLimit().intValue() > 0) {
                    sql.append("and \n");
                    switch (condition.getTimeLimit().intValue()) {
                    case 1:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 1 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 2:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 3 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 3:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 6 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 4:
                        sql.append("  date_format(create_date, '%Y') = date_format(now(), '%Y') \n");
                        break;
                    case 5:
                        sql.append("  date_format(create_date, '%Y') < date_format(now(), '%Y') \n");
                        break;
                    default:
                        break;
                    }
                }
            }
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#countByCnd] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            
            if (condition != null) {
                int index = 0;
                if (StringUtils.isNotEmpty(condition.getTenderTitle())) {
                    statement.setString(++index, "%" + condition.getTenderTitle() + "%");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateFrom())) {
                    statement.setString(++index, condition.getEnrollStartDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateTo())) {
                    statement.setString(++index, condition.getEnrollStartDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateFrom())) {
                    statement.setString(++index, condition.getEnrollEndDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateTo())) {
                    statement.setString(++index, condition.getEnrollEndDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateFrom())) {
                    statement.setString(++index, condition.getTenderEndDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateTo())) {
                    statement.setString(++index, condition.getTenderEndDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateFrom())) {
                    statement.setString(++index, condition.getPublishResultDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateTo())) {
                    statement.setString(++index, condition.getPublishResultDateTo());
                }
                if (condition.getTenderPattern() != null && condition.getTenderPattern().intValue() > 0) {
                    statement.setInt(++index, condition.getTenderPattern());
                }
                if (condition.getStatus() != null && condition.getStatus().length > 0) {
                    for (Integer status : condition.getStatus()) {
                        statement.setInt(++index, status);
                    }
                }
            }
            
            ResultSet resultSet = statement.executeQuery();
            
            if (resultSet.next()) {
                count = resultSet.getInt("count");
            }
            
            return count;
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#countByCnd] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#countByCnd] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public List<TenderDetail> searchByCnd(TenderCondition condition) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#searchByCnd] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  tender_id, \n")
                .append("  tender_no, \n")
                .append("  status, \n")
                .append("  status_name, \n")
                .append("  tender_title, \n")
                .append("  enroll_start_date, \n")
                .append("  enroll_end_date, \n")
                .append("  tender_end_date, \n")
                .append("  publish_result_date, \n")
                .append("  content_description, \n")
                .append("  vendor_requirement, \n")
                .append("  tender_pattern, \n")
                .append("  tender_pattern_name, \n")
                .append("  tender_template, \n")
                .append("  contact_name, \n")
                .append("  contact_tel, \n")
                .append("  enroll_count, \n")
                .append("  finalist_count, \n")
                .append("  quote_count, \n")
                .append("  enroll_start_remaining, \n")
                .append("  enroll_end_remaining, \n")
                .append("  tender_end_remaining, \n")
                .append("  publish_result_remaining, \n")
                .append("  create_user, \n")
                .append("  create_date, \n")
                .append("  update_user, \n")
                .append("  update_date, \n")
                .append("  delete_flag \n")
                .append("from \n")
                .append("  v_tender_information \n")
                .append("where \n")
                .append("  delete_flag = false \n");
            
            if (condition != null) {
                if (StringUtils.isNotEmpty(condition.getTenderTitle())) {
                    sql.append("and \n");
                    sql.append("  tender_title like ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateFrom())) {
                    sql.append("and \n");
                    sql.append("  enroll_start_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateTo())) {
                    sql.append("and \n");
                    sql.append("  enroll_start_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateFrom())) {
                    sql.append("and \n");
                    sql.append("  enroll_end_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateTo())) {
                    sql.append("and \n");
                    sql.append("  enroll_end_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateFrom())) {
                    sql.append("and \n");
                    sql.append("  tender_end_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateTo())) {
                    sql.append("and \n");
                    sql.append("  tender_end_date <= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateFrom())) {
                    sql.append("and \n");
                    sql.append("  publish_result_date >= ? \n");
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateTo())) {
                    sql.append("and \n");
                    sql.append("  publish_result_date <= ? \n");
                }
                if (condition.getTenderPattern() != null && condition.getTenderPattern().intValue() > 0) {
                    sql.append("and \n");
                    sql.append("  tender_pattern = ? \n");
                }
                if (condition.getStatus() != null && condition.getStatus().length > 0) {
                    sql.append("and \n");
                    String strStatus = "";
                    for (int i = 0; i < condition.getStatus().length; i++) {
                        if (i == 0) {
                            strStatus = "?";
                        } else {
                            strStatus += ", ?";
                        }
                    }
                    sql.append("  status in (" + strStatus + ") \n");
                }
                if (condition.getTimeLimit() != null && condition.getTimeLimit().intValue() > 0) {
                    sql.append("and \n");
                    switch (condition.getTimeLimit().intValue()) {
                    case 1:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 1 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 2:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 3 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 3:
                        sql.append("  date_format(create_date, '%Y-%m-%d') >= date_format(date_add(date_sub(now(), interval 6 month), interval 1 day), '%Y-%m-%d') \n");
                        break;
                    case 4:
                        sql.append("  date_format(create_date, '%Y') = date_format(now(), '%Y') \n");
                        break;
                    case 5:
                        sql.append("  date_format(create_date, '%Y') < date_format(now(), '%Y') \n");
                        break;
                    default:
                        break;
                    }
                }
            }
            
            sql.append("order by \n");
            sql.append("  create_date desc \n");
            
            if (condition != null) {
                if (condition.getPage() != null && condition.getRows() != null && condition.getPage() > 0 && condition.getRows() > 0) {
                    sql.append("limit ?, ? \n");
                }
            }
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#searchByCnd] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            
            if (condition != null) {
                int index = 0;
                if (StringUtils.isNotEmpty(condition.getTenderTitle())) {
                    statement.setString(++index, "%" + condition.getTenderTitle() + "%");
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateFrom())) {
                    statement.setString(++index, condition.getEnrollStartDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollStartDateTo())) {
                    statement.setString(++index, condition.getEnrollStartDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateFrom())) {
                    statement.setString(++index, condition.getEnrollEndDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getEnrollEndDateTo())) {
                    statement.setString(++index, condition.getEnrollEndDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateFrom())) {
                    statement.setString(++index, condition.getTenderEndDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getTenderEndDateTo())) {
                    statement.setString(++index, condition.getTenderEndDateTo());
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateFrom())) {
                    statement.setString(++index, condition.getPublishResultDateFrom());
                }
                if (StringUtils.isNotEmpty(condition.getPublishResultDateTo())) {
                    statement.setString(++index, condition.getPublishResultDateTo());
                }
                if (condition.getTenderPattern() != null && condition.getTenderPattern().intValue() > 0) {
                    statement.setInt(++index, condition.getTenderPattern());
                }
                if (condition.getStatus() != null && condition.getStatus().length > 0) {
                    for (Integer status : condition.getStatus()) {
                        statement.setInt(++index, status);
                    }
                }
                if (condition.getPage() != null && condition.getRows() != null && condition.getPage() > 0 && condition.getRows() > 0) {
                    statement.setInt(++index, (condition.getPage() - 1) * condition.getRows());
                    statement.setInt(++index, condition.getRows());
                }
            }
            
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderDetail> resultSetMapper = new ResultSetMapper<TenderDetail>();
            List<TenderDetail> tenderDetailList = resultSetMapper.mapResultSetToList(resultSet, TenderDetail.class);
            
            return tenderDetailList;
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#searchByCnd] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#searchByCnd] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public Boolean insertTenderInformation(TenderDetail tenderDetail, String createUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderInformation] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_information ( \n")
                .append("  tender_no, \n")
                .append("  status, \n")
                .append("  tender_title, \n")
                .append("  enroll_start_date, \n")
                .append("  enroll_end_date, \n")
                .append("  tender_end_date, \n")
                .append("  publish_result_date, \n")
                .append("  content_description, \n")
                .append("  vendor_requirement, \n")
                .append("  tender_pattern, \n")
                .append("  tender_template, \n")
                .append("  contact_name, \n")
                .append("  contact_tel, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  concat(date_format(now(), '%Y%m%d'), get_random(4)), \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderInformation] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderDetail.getStatus());
            statement.setString(2, tenderDetail.getTenderTitle());
            statement.setString(3, tenderDetail.getEnrollStartDate());
            statement.setString(4, tenderDetail.getEnrollEndDate());
            statement.setString(5, tenderDetail.getTenderEndDate());
            statement.setString(6, tenderDetail.getPublishResultDate());
            statement.setString(7, tenderDetail.getContentDescription());
            statement.setString(8, tenderDetail.getVendorRequirement());
            statement.setInt(9, tenderDetail.getTenderPattern());
            statement.setInt(10, 0);
            statement.setString(11, tenderDetail.getContactName());
            statement.setString(12, tenderDetail.getContactTel());
            statement.setString(13, createUser);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderInformation] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderInformation] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean insertTenderProduct(TenderProduct tenderProduct, String createUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderProduct] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_product ( \n")
                .append("  tender_id, \n")
                .append("  product_name, \n")
                .append("  quantity, \n")
                .append("  unit, \n")
                .append("  product_description, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderProduct] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderProduct.getTenderId());
            statement.setString(2, tenderProduct.getProductName());
            statement.setInt(3, tenderProduct.getQuantity());
            statement.setString(4, tenderProduct.getUnit());
            statement.setString(5, tenderProduct.getProductDescription());
            statement.setString(6, createUser);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderProduct] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderProduct] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean insertTenderEnroll(TenderEnroll tenderEnroll, String createUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderEnroll] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_enroll ( \n")
                .append("  tender_id, \n")
                .append("  member_login_name, \n")
                .append("  finalist_flag, \n")
                .append("  invite_flag, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderEnroll] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderEnroll.getTenderId());
            statement.setString(2, tenderEnroll.getMemberLoginName());
            statement.setBoolean(3, tenderEnroll.getFinalistFlag());
            statement.setBoolean(4, tenderEnroll.getInviteFlag());
            statement.setString(5, createUser);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderEnroll] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderEnroll] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean insertTenderFinalist(TenderFinalist tenderFinalist, String createUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderFinalist] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_finalist ( \n")
                .append("  tender_id, \n")
                .append("  member_login_name, \n")
                .append("  quote_flag, \n")
                .append("  invite_flag, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderFinalist] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderFinalist.getTenderId());
            statement.setString(2, tenderFinalist.getMemberLoginName());
            statement.setBoolean(3, tenderFinalist.getQuoteFlag());
            statement.setBoolean(4, tenderFinalist.getInviteFlag());
            statement.setString(5, createUser);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderFinalist] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderFinalist] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean insertTenderBid(TenderBid tenderBid, String createUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderBid] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_bid ( \n")
                .append("  tender_id, \n")
                .append("  member_login_name, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderBid] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderBid.getTenderId());
            statement.setString(2, tenderBid.getMemberLoginName());
            statement.setString(3, createUser);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderBid] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderBid] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean deleteTenderBid(Integer tenderId, String memberLoginName) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#deleteTenderBid] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("delete from t_tender_bid \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  member_login_name = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderBid] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            statement.setString(2, memberLoginName);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderBid] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#deleteTenderBid] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public List<TenderProduct> findProduct(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findProduct] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  product_id, \n")
                .append("  tender_id, \n")
                .append("  product_name, \n")
                .append("  quantity, \n")
                .append("  unit, \n")
                .append("  product_description, \n")
                .append("  create_user, \n")
                .append("  create_date, \n")
                .append("  update_user, \n")
                .append("  update_date, \n")
                .append("  delete_flag \n")
                .append("from \n")
                .append("  t_tender_product \n")
                .append("where \n")
                .append("  delete_flag = false \n")
                .append("and \n")
                .append("  tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findProduct] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderProduct> resultSetMapper = new ResultSetMapper<TenderProduct>();
            List<TenderProduct> tenderProductList = resultSetMapper.mapResultSetToList(resultSet, TenderProduct.class);
            return tenderProductList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findProduct] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findProduct] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public TenderDetail findDetail(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findDetail] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  tender_id, \n")
                .append("  tender_no, \n")
                .append("  status, \n")
                .append("  status_name, \n")
                .append("  tender_title, \n")
                .append("  enroll_start_date, \n")
                .append("  enroll_end_date, \n")
                .append("  tender_end_date, \n")
                .append("  publish_result_date, \n")
                .append("  content_description, \n")
                .append("  vendor_requirement, \n")
                .append("  tender_pattern, \n")
                .append("  tender_pattern_name, \n")
                .append("  tender_template, \n")
                .append("  contact_name, \n")
                .append("  contact_tel, \n")
                .append("  enroll_count, \n")
                .append("  finalist_count, \n")
                .append("  quote_count, \n")
                .append("  enroll_start_remaining, \n")
                .append("  enroll_end_remaining, \n")
                .append("  tender_end_remaining, \n")
                .append("  publish_result_remaining, \n")
                .append("  create_user, \n")
                .append("  create_date, \n")
                .append("  update_user, \n")
                .append("  update_date, \n")
                .append("  delete_flag \n")
                .append("from \n")
                .append("  v_tender_information \n")
                .append("where \n")
                .append("  delete_flag = false \n")
                .append("and \n")
                .append("  tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findDetail] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderDetail> resultSetMapper = new ResultSetMapper<TenderDetail>();
            TenderDetail tenderDetail = resultSetMapper.mapResultSetToObject(resultSet, TenderDetail.class);
            
            return tenderDetail;
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findDetail] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findDetail] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public TenderMemberStatus findTenderMemberStatus(Integer tenderId, String memberLoginName) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findTenderMemberStatus] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  vti.tender_id, \n")
                .append("  if(isnull(tte.member_login_name), false, true) as enroll_flag, \n")
                .append("  if(isnull(ttf.member_login_name), false, true) as finalist_flag, \n")
                .append("  if(isnull(ttq.member_login_name), false, true) as quote_flag, \n")
                .append("  if(isnull(ttb.member_login_name), false, true) as bid_flag \n")
                .append("from \n")
                .append("  v_tender_information vti \n")
                .append("left join \n")
                .append("  t_tender_enroll tte \n")
                .append("on \n")
                .append("  (tte.delete_flag = false \n")
                .append("and \n")
                .append("  tte.tender_id = vti.tender_id \n")
                .append("and \n")
                .append("  tte.member_login_name = ?) \n")
                .append("left join \n")
                .append("  t_tender_finalist ttf \n")
                .append("on \n")
                .append("  (ttf.delete_flag = false \n")
                .append("and \n")
                .append("  ttf.tender_id = vti.tender_id \n")
                .append("and \n")
                .append("  ttf.member_login_name = ?) \n")
                .append("left join \n")
                .append("  t_tender_quote ttq \n")
                .append("on \n")
                .append("  (ttq.delete_flag = false \n")
                .append("and \n")
                .append("  ttq.tender_id = vti.tender_id \n")
                .append("and \n")
                .append("  ttq.member_login_name = ?) \n")
                .append("left join \n")
                .append("  t_tender_bid ttb \n")
                .append("on \n")
                .append("  (ttb.delete_flag = false \n")
                .append("and \n")
                .append("  ttb.tender_id = vti.tender_id \n")
                .append("and \n")
                .append("  ttb.member_login_name = ?) \n")
                .append("where \n")
                .append("  vti.delete_flag = false \n")
                .append("and \n")
                .append("  vti.tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findTenderMemberStatus] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setString(1, memberLoginName);
            statement.setString(2, memberLoginName);
            statement.setString(3, memberLoginName);
            statement.setString(4, memberLoginName);
            statement.setInt(5, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderMemberStatus> resultSetMapper = new ResultSetMapper<TenderMemberStatus>();
            TenderMemberStatus tenderMemberStatus = resultSetMapper.mapResultSetToObject(resultSet, TenderMemberStatus.class);
            
            return tenderMemberStatus;
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findTenderMemberStatus] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findTenderMemberStatus] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public Boolean insertTenderQuote(TenderQuote tenderQuote) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderQuote] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_quote ( \n")
                .append("  tender_id, \n")
                .append("  member_login_name, \n")
                .append("  quote_date, \n")
                .append("  total_price, \n")
                .append("  bid_flag, \n")
                .append("  comment, \n")
                .append("  tender_doc, \n")
                .append("  create_user) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  current_timestamp, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderQuote] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderQuote.getTenderId());
            statement.setString(2, tenderQuote.getMemberLoginName());
            statement.setDouble(3, tenderQuote.getTotalPrice());
            statement.setBoolean(4, false);
            statement.setString(5, tenderQuote.getComment());
            statement.setInt(6, tenderQuote.getTenderDoc());
            statement.setString(7, tenderQuote.getCreateUser());
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderQuote] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderQuote] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean insertTenderQuoteDetail(TenderQuoteDetail tenderQuoteDetail) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#insertTenderQuoteDetail] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("insert into t_tender_quote_detail ( \n")
                .append("  tender_id, \n")
                .append("  product_id, \n")
                .append("  member_login_name, \n")
                .append("  unit_price, \n")
                .append("  total_price) \n")
                .append("values ( \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?, \n")
                .append("  ?) \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderQuoteDetail] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderQuoteDetail.getTenderId());
            statement.setInt(2, tenderQuoteDetail.getProductId());
            statement.setString(3, tenderQuoteDetail.getMemberLoginName());
            statement.setDouble(4, tenderQuoteDetail.getUnitPrice());
            statement.setDouble(5, tenderQuoteDetail.getTotalPrice());
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#insertTenderQuoteDetail] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#insertTenderQuoteDetail] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean updateFinalistFlag(Integer tenderId, String memberLoginName, Boolean finalistFlag, String updateUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#updateFinalistFlag] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update \n")
                .append("  t_tender_enroll \n")
                .append("set \n")
                .append("  finalist_flag = ?, \n")
                .append("  update_user = ?, \n")
                .append("  update_date = current_timestamp \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  member_login_name = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateFinalistFlag] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setBoolean(1, finalistFlag);
            statement.setString(2, updateUser);
            statement.setInt(3, tenderId);
            statement.setString(4, memberLoginName);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateFinalistFlag] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#updateFinalistFlag] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean updateQuoteFlag(Integer tenderId, String memberLoginName, Boolean quoteFlag, String updateUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#updateQuoteFlag] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update \n")
                .append("  t_tender_finalist \n")
                .append("set \n")
                .append("  quote_flag = ?, \n")
                .append("  update_user = ?, \n")
                .append("  update_date = current_timestamp \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  member_login_name = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateQuoteFlag] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setBoolean(1, quoteFlag);
            statement.setString(2, updateUser);
            statement.setInt(3, tenderId);
            statement.setString(4, memberLoginName);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateQuoteFlag] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#updateQuoteFlag] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean updateBidFlag(Integer tenderId, String memberLoginName, Boolean bidFlag, String updateUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#updateBidFlag] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update \n")
                .append("  t_tender_quote \n")
                .append("set \n")
                .append("  bid_flag = ?, \n")
                .append("  update_user = ?, \n")
                .append("  update_date = current_timestamp \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  member_login_name = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateBidFlag] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setBoolean(1, bidFlag);
            statement.setString(2, updateUser);
            statement.setInt(3, tenderId);
            statement.setString(4, memberLoginName);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateBidFlag] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#updateBidFlag] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean bindTemplate(Integer tenderId, Integer attachmentId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#bindTemplate] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update \n")
                .append("  t_tender_information \n")
                .append("set \n")
                .append("  tender_template = ? \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#bindTemplate] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, attachmentId);
            statement.setInt(2, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#bindTemplate] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#bindTemplate] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean deleteTemplate(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#deleteTemplate] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update \n")
                .append("  t_tender_information \n")
                .append("set \n")
                .append("  tender_template = null \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTemplate] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTemplate] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#deleteTemplate] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public List<TenderInvite> findInvite(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findInvite] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  tender_id, \n")
                .append("  member_login_name \n")
                .append("from \n")
                .append("  v_tender_invite \n")
                .append("where \n")
                .append("  tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findInvite] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderInvite> resultSetMapper = new ResultSetMapper<TenderInvite>();
            List<TenderInvite> tenderInviteList = resultSetMapper.mapResultSetToList(resultSet, TenderInvite.class);
            return tenderInviteList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findInvite] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findInvite] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public Boolean updateTenderInformation(TenderDetail tenderDetail, String updateUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#updateTenderInformation] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update t_tender_information \n")
                .append("set \n")
                .append("  status = ?, \n")
                .append("  tender_title = ?, \n")
                .append("  enroll_start_date = ?, \n")
                .append("  enroll_end_date = ?, \n")
                .append("  tender_end_date = ?, \n")
                .append("  publish_result_date = ?, \n")
                .append("  content_description = ?, \n")
                .append("  vendor_requirement = ?, \n")
                .append("  tender_pattern = ?, \n")
                .append("  tender_template = ?, \n")
                .append("  contact_name = ?, \n")
                .append("  contact_tel = ?, \n")
                .append("  update_user = ?, \n")
                .append("  update_date = current_timestamp \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateTenderInformation] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderDetail.getStatus());
            statement.setString(2, tenderDetail.getTenderTitle());
            statement.setString(3, tenderDetail.getEnrollStartDate());
            statement.setString(4, tenderDetail.getEnrollEndDate());
            statement.setString(5, tenderDetail.getTenderEndDate());
            statement.setString(6, tenderDetail.getPublishResultDate());
            statement.setString(7, tenderDetail.getContentDescription());
            statement.setString(8, tenderDetail.getVendorRequirement());
            statement.setInt(9, tenderDetail.getTenderPattern());
            statement.setInt(10, 0);
            statement.setString(11, tenderDetail.getContactName());
            statement.setString(12, tenderDetail.getContactTel());
            statement.setString(13, updateUser);
            statement.setInt(14, tenderDetail.getTenderId());
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#updateTenderInformation] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#updateTenderInformation] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean deleteTenderProduct(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#deleteTenderProduct] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("delete from t_tender_product \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderProduct] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count >= 0) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderProduct] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#deleteTenderProduct] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean deleteTenderInvite(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#deleteTenderInvite] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("delete \n")
                .append("  tte.*, \n")
                .append("  ttf.* \n")
                .append("from \n")
                .append("  t_tender_enroll tte, \n")
                .append("  t_tender_finalist ttf \n")
                .append("where \n")
                .append("  tte.tender_id = ? \n")
                .append("and \n")
                .append("  tte.invite_flag = true \n")
                .append("and \n")
                .append("  ttf.tender_id = ? \n")
                .append("and \n")
                .append("  ttf.invite_flag = true \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderInvite] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            statement.setInt(2, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count >= 0) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderInvite] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#deleteTenderInvite] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean deleteTenderInformation(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#deleteTenderInformation] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("delete from t_tender_information \n")
                .append("where \n")
                .append("  tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderInformation] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#deleteTenderInformation] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#deleteTenderInformation] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public Boolean changeStatus(Integer tenderId, Integer status, String updateUser) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#changeStatus] start.");
        }

        PreparedStatement statement = null;
        Boolean result = false;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("update t_tender_information \n")
                .append("set \n")
                .append("  status = ?, \n")
                .append("  update_user = ?, \n")
                .append("  update_date = current_timestamp \n")
                .append("where \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  delete_flag = false \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#changeStatus] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, status);
            statement.setString(2, updateUser);
            statement.setInt(3, tenderId);
            
            int count = statement.executeUpdate();
            
            if (count == 1) {
                result = true;
            }
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#changeStatus] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#changeStatus] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
        return result;
    }

    @Override
    public List<Member> findEnrollMember(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findEnrollMember] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  tte.member_login_name, \n")
                .append("  vm.license_number, \n")
                .append("  vm.enterprise_name, \n")
                .append("  vm.enterprise_property, \n")
                .append("  vm.enterprise_property_name, \n")
                .append("  vm.enterprise_category, \n")
                .append("  vm.enterprise_category_name, \n")
                .append("  vm.contact_name, \n")
                .append("  vm.contact_certificates_type, \n")
                .append("  vm.contact_certificates_type_name, \n")
                .append("  vm.contact_certificates_no, \n")
                .append("  vm.area_code, \n")
                .append("  vm.telephone, \n")
                .append("  vm.mobile, \n")
                .append("  vm.mobile_certificated, \n")
                .append("  vm.email, \n")
                .append("  vm.email_certificated, \n")
                .append("  vm.qq_no, \n")
                .append("  vm.weixin_no, \n")
                .append("  vm.legal_name, \n")
                .append("  vm.legal_certificates_type, \n")
                .append("  vm.legal_certificates_type_name, \n")
                .append("  vm.legal_certificates_no, \n")
                .append("  vm.image_contact_certificates_front, \n")
                .append("  vm.image_contact_certificates_back, \n")
                .append("  vm.image_legal_certificates_front, \n")
                .append("  vm.image_legal_certificates_back, \n")
                .append("  vm.image_license, \n")
                .append("  vm.points, \n")
                .append("  vm.rank, \n")
                .append("  vm.rank_name, \n")
                .append("  tte.finalist_flag \n")
                .append("from \n")
                .append("  t_tender_enroll tte \n")
                .append("join \n")
                .append("  v_member vm \n")
                .append("on \n")
                .append("  tte.member_login_name = vm.member_login_name \n")
                .append("where \n")
                .append("  tte.tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findEnrollMember] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<Member> resultSetMapper = new ResultSetMapper<Member>();
            List<Member> memberList = resultSetMapper.mapResultSetToList(resultSet, Member.class);
            return memberList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findEnrollMember] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findEnrollMember] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public List<Member> findFinalistMember(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findFinalistMember] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  ttf.member_login_name, \n")
                .append("  vm.license_number, \n")
                .append("  vm.enterprise_name, \n")
                .append("  vm.enterprise_property, \n")
                .append("  vm.enterprise_property_name, \n")
                .append("  vm.enterprise_category, \n")
                .append("  vm.enterprise_category_name, \n")
                .append("  vm.contact_name, \n")
                .append("  vm.contact_certificates_type, \n")
                .append("  vm.contact_certificates_type_name, \n")
                .append("  vm.contact_certificates_no, \n")
                .append("  vm.area_code, \n")
                .append("  vm.telephone, \n")
                .append("  vm.mobile, \n")
                .append("  vm.mobile_certificated, \n")
                .append("  vm.email, \n")
                .append("  vm.email_certificated, \n")
                .append("  vm.qq_no, \n")
                .append("  vm.weixin_no, \n")
                .append("  vm.legal_name, \n")
                .append("  vm.legal_certificates_type, \n")
                .append("  vm.legal_certificates_type_name, \n")
                .append("  vm.legal_certificates_no, \n")
                .append("  vm.image_contact_certificates_front, \n")
                .append("  vm.image_contact_certificates_back, \n")
                .append("  vm.image_legal_certificates_front, \n")
                .append("  vm.image_legal_certificates_back, \n")
                .append("  vm.image_license, \n")
                .append("  vm.points, \n")
                .append("  vm.rank, \n")
                .append("  vm.rank_name, \n")
                .append("  ttf.quote_flag \n")
                .append("from \n")
                .append("  t_tender_finalist ttf \n")
                .append("join \n")
                .append("  v_member vm \n")
                .append("on \n")
                .append("  ttf.member_login_name = vm.member_login_name \n")
                .append("where \n")
                .append("  ttf.tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findFinalistMember] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<Member> resultSetMapper = new ResultSetMapper<Member>();
            List<Member> memberList = resultSetMapper.mapResultSetToList(resultSet, Member.class);
            return memberList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findFinalistMember] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findFinalistMember] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public List<Member> findQuoteMember(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findQuoteMember] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  ttq.member_login_name, \n")
                .append("  vm.license_number, \n")
                .append("  vm.enterprise_name, \n")
                .append("  vm.enterprise_property, \n")
                .append("  vm.enterprise_property_name, \n")
                .append("  vm.enterprise_category, \n")
                .append("  vm.enterprise_category_name, \n")
                .append("  vm.contact_name, \n")
                .append("  vm.contact_certificates_type, \n")
                .append("  vm.contact_certificates_type_name, \n")
                .append("  vm.contact_certificates_no, \n")
                .append("  vm.area_code, \n")
                .append("  vm.telephone, \n")
                .append("  vm.mobile, \n")
                .append("  vm.mobile_certificated, \n")
                .append("  vm.email, \n")
                .append("  vm.email_certificated, \n")
                .append("  vm.qq_no, \n")
                .append("  vm.weixin_no, \n")
                .append("  vm.legal_name, \n")
                .append("  vm.legal_certificates_type, \n")
                .append("  vm.legal_certificates_type_name, \n")
                .append("  vm.legal_certificates_no, \n")
                .append("  vm.image_contact_certificates_front, \n")
                .append("  vm.image_contact_certificates_back, \n")
                .append("  vm.image_legal_certificates_front, \n")
                .append("  vm.image_legal_certificates_back, \n")
                .append("  vm.image_license, \n")
                .append("  vm.points, \n")
                .append("  vm.rank, \n")
                .append("  vm.rank_name, \n")
                .append("  ttq.total_price, \n")
                .append("  ttq.bid_flag \n")
                .append("from \n")
                .append("  t_tender_quote ttq \n")
                .append("join \n")
                .append("  v_member vm \n")
                .append("on \n")
                .append("  ttq.member_login_name = vm.member_login_name \n")
                .append("where \n")
                .append("  ttq.tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuoteMember] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<Member> resultSetMapper = new ResultSetMapper<Member>();
            List<Member> memberList = resultSetMapper.mapResultSetToList(resultSet, Member.class);
            return memberList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuoteMember] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findQuoteMember] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public Member findBidMember(Integer tenderId) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findBidMember] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  ttb.member_login_name, \n")
                .append("  ttq.total_price, \n")
                .append("  vm.license_number, \n")
                .append("  vm.enterprise_name, \n")
                .append("  vm.enterprise_property, \n")
                .append("  vm.enterprise_property_name, \n")
                .append("  vm.enterprise_category, \n")
                .append("  vm.enterprise_category_name, \n")
                .append("  vm.contact_name, \n")
                .append("  vm.contact_certificates_type, \n")
                .append("  vm.contact_certificates_type_name, \n")
                .append("  vm.contact_certificates_no, \n")
                .append("  vm.area_code, \n")
                .append("  vm.telephone, \n")
                .append("  vm.mobile, \n")
                .append("  vm.mobile_certificated, \n")
                .append("  vm.email, \n")
                .append("  vm.email_certificated, \n")
                .append("  vm.qq_no, \n")
                .append("  vm.weixin_no, \n")
                .append("  vm.legal_name, \n")
                .append("  vm.legal_certificates_type, \n")
                .append("  vm.legal_certificates_type_name, \n")
                .append("  vm.legal_certificates_no, \n")
                .append("  vm.image_contact_certificates_front, \n")
                .append("  vm.image_contact_certificates_back, \n")
                .append("  vm.image_legal_certificates_front, \n")
                .append("  vm.image_legal_certificates_back, \n")
                .append("  vm.image_license, \n")
                .append("  vm.points, \n")
                .append("  vm.rank, \n")
                .append("  vm.rank_name \n")
                .append("from \n")
                .append("  t_tender_bid ttb \n")
                .append("join \n")
                .append("  v_member vm \n")
                .append("on \n")
                .append("  ttb.member_login_name = vm.member_login_name \n")
                .append("join \n")
                .append("  t_tender_quote ttq \n")
                .append("on \n")
                .append("  ttb.tender_id = ttq.tender_id \n")
                .append("and \n")
                .append("  ttb.member_login_name = ttq.member_login_name \n")
                .append("where \n")
                .append("  ttb.tender_id = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findBidMember] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<Member> resultSetMapper = new ResultSetMapper<Member>();
            Member member = resultSetMapper.mapResultSetToObject(resultSet, Member.class);
            return member;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findBidMember] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findBidMember] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public List<TenderQuoteDetail> findQuoteDetail(Integer tenderId, String memberLoginName) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findQuoteDetail] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  ttqd.tender_id, \n")
                .append("  ttqd.member_login_name, \n")
                .append("  ttqd.product_id, \n")
                .append("  ttp.product_name, \n")
                .append("  ttqd.unit_price, \n")
                .append("  ttqd.total_price, \n")
                .append("  ttp.quantity, \n")
                .append("  ttp.unit \n")
                .append("from \n")
                .append("  t_tender_quote_detail ttqd \n")
                .append("join \n")
                .append("  t_tender_product ttp \n")
                .append("on \n")
                .append("  ttqd.tender_id = ttp.tender_id \n")
                .append("and \n")
                .append("  ttqd.product_id = ttp.product_id \n")
                .append("where \n")
                .append("  ttqd.tender_id = ? \n")
                .append("and \n")
                .append("  ttqd.member_login_name = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuoteDetail] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            statement.setString(2, memberLoginName);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderQuoteDetail> resultSetMapper = new ResultSetMapper<TenderQuoteDetail>();
            List<TenderQuoteDetail> tenderQuoteDetailList = resultSetMapper.mapResultSetToList(resultSet, TenderQuoteDetail.class);
            return tenderQuoteDetailList;
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuoteDetail] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findQuoteDetail] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

    @Override
    public TenderQuote findQuote(Integer tenderId, String memberLoginName) {
        if (logger.isInfoEnabled()) {
            logger.info("[TenderDao_JDBCImpl#findQuote] start.");
        }

        PreparedStatement statement = null;
        
        try {
            
            StringBuilder sql = new StringBuilder()
                .append("select \n")
                .append("  tender_id, \n")
                .append("  member_login_name, \n")
                .append("  quote_date, \n")
                .append("  total_price, \n")
                .append("  bid_flag, \n")
                .append("  comment, \n")
                .append("  tender_doc, \n")
                .append("  create_user, \n")
                .append("  create_date, \n")
                .append("  update_user, \n")
                .append("  update_date, \n")
                .append("  delete_flag \n")
                .append("from \n")
                .append("  t_tender_quote \n")
                .append("where \n")
                .append("  delete_flag = false \n")
                .append("and \n")
                .append("  tender_id = ? \n")
                .append("and \n")
                .append("  member_login_name = ? \n");
            
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuote] sql={}", sql);
            }
            
            Connection connection = DatabaseSessionManager.getInstance().getSession();
            statement = connection.prepareStatement(sql.toString());
            statement.setInt(1, tenderId);
            statement.setString(2, memberLoginName);
            ResultSet resultSet = statement.executeQuery();
            ResultSetMapper<TenderQuote> resultSetMapper = new ResultSetMapper<TenderQuote>();
            TenderQuote tenderQuote = resultSetMapper.mapResultSetToObject(resultSet, TenderQuote.class);
            
            return tenderQuote;
            
        } catch (SQLException e) {
            if (logger.isTraceEnabled()) {
                logger.trace("[TenderDao_JDBCImpl#findQuote] sql error occurred.", e);
            }
            throw new DatabaseException("database error occurred.", e);
        } finally {
            if (logger.isInfoEnabled()) {
                logger.info("[TenderDao_JDBCImpl#findQuote] finish.");
            }
            if (statement != null) { try { statement.close(); } catch (SQLException e) {} }
        }
    }

}
